﻿/////////////////////////////////////////////////////////////////////////
//                                                                     //
//    MTGProject - A Magic The Gathering Networked Environment         //
//                                                                     //
//        Copyright (c) 2008 by The MTGProject Team (CSC230)           //
//                                                                     //
// This file is part of MTGProject.                                    //
//                                                                     //
// MTGProject is free software; you can redistribute it and/or         //
// modify it under the terms of the GNU Lesser General Public          //
// License as published by the Free Software Foundation; either        //
// version 3 of the License, or (at your option) any later version.    //
//                                                                     //
// This library is distributed in the hope that it will be useful,     //
// but WITHOUT ANY WARRANTY; without even the implied warranty of      //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       //
// GNU Lesser General Public License for more details.                 //
//                                                                     //
// You should have received a copy of the GNU Lesser General Public    //
// License along with this library; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA           //
// 02111-1307, USA, or contact the author(s):                          //
//                                                                     //
// Ruben Acuna <flyingfowlsoftware@earthlink.net>                      //
// Ryan Costello <fusioncobra@yahoo.com>                               //
// Chris Watson <the5thdimension@hotmail.com>                          //
//                                                                     //
/////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;

namespace MTGProject
{
    class PlayerControllerDebug : PlayerController
    {
        #region variables

        Player puppet;

        #endregion

        #region properties

        public override Player Puppet
        {
            get { return puppet; }
            set { puppet = value; }
        }

        public override bool IsConnected
        {
            get { return true; }
            set { }
        }

        #endregion

        #region constructor

        public PlayerControllerDebug(Player player, string deck)
        {
            Puppet = player;
            Puppet.Deck = CardIO.LoadXMLDeck(deck);
        }

        #endregion

        #region interface methods

        public override void PhaseMain()
        {
            UtilDebug.printPlayer(Puppet);
            System.Console.WriteLine("Start main phase: Type the name of a card to play or tap (e.g. 'tap mountain', or "
                                   + "'play mountain'. Press q when done with main phase.");

            string input = "";

            while (!(input.Equals("q")))
            {
                input = System.Console.ReadLine().ToLower();

                if (input.Contains("play"))
                {
                    string cardName = input.Substring(input.IndexOf(' ') + 1);

                    ICard card = Puppet.Hand.GetCardByName(cardName);

                    if (card != null)
                        Puppet.PlayCard(card);
                    else
                        System.Console.WriteLine("  " + cardName + " does not exist.");
                }
                else if (input.Contains("tap"))
                {
                    string cardName = input.Substring(input.IndexOf(' ') + 1);
                    IPermanent card = null;

                    foreach (IPermanent permanent in Puppet.Permanents.Cards)
                    {
                        if ((permanent.IsTapped == false) && permanent.Name.ToLower().Equals(cardName))
                        {
                            card = permanent;
                            break;
                        }
                    }

                    if (card != null)
                        Puppet.TapCard(card);
                    else
                        System.Console.WriteLine("  No untapped " + cardName + "'s are in play.");
                }
                else
                    if (!input.Split(' ')[0].Equals("q"))
                        System.Console.WriteLine(input.Split(' ')[0] + " is not a valid action.");
            }

            System.Console.WriteLine("End of main phase.");
        }

        //removed
        public override void PhaseCombatStart()
        {
        }

        //removed
        public override CardCreature PhaseCombatRequestAttackingCreature()
        {
            return null;
        }

        //removed
        public override void PhaseCombatEnd()
        {
        }

        //removed
        public override int PhaseDefense(LinkedList<CardCreature> unblockedAttackers)
        {
            return 0;
        }

        //removed
        public override void OnLose()
        {
        }

        //removed
        public override void OnWin()
        {
        }

        public override ICard SelectCard(LinkedList<ICard> cards)
        {
            return SelectCard(cards, "");
        }

        public override ICard SelectCard(LinkedList<ICard> cards, string message)
        {
            if (message.Length > 0)
                Tell(message);

            return cards.First.Value;
        }

        //removed
        public override void Tell(string message)
        {
        }

        #endregion

    }
}
